﻿<?php

// επιλογή Βάσης Δεδομένων και συγγραφή του ερωτήματος sql
$db_host='localhost';
$db_database='creperi';
$db_username='root';
$db_password='';
$connection=mysql_connect($db_host,$db_username,$db_password);
if (!$connection)
{
	die ("Couldn't Connect to the Database: <br>".mysql_error());
}
$db_select=mysql_select_db($db_database);
mysql_query("SET NAMES utf8");

if (!$db_select)
{
	die ("Couldn't select db: <br>".mysql_error());
}

$query="select material_id,material_name,material_price,material_type from materials";
//----------------------------------------------------

// αρχικοποίηση μεταβλητών
$count_materials="";
$count_names="";
$count_prices="";
//----------------------------------------------------

// για τα τυριά
$result=mysql_query($query,$connection) or Die (mysql_error());
echo "	<tr>
			<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Τυριά </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Cheese")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
									</th> 
								</tr>";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>";
//-------------------------------------------------------------------------------------------------------------------

// για τα αλλαντικά
$result=mysql_query($query,$connection) or Die (mysql_error());
	echo "	<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Αλλαντικά </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Charcuterie")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>";
//-------------------------------------------------------------------------------------------------------------------

// για τις αλοιφές
$result=mysql_query($query,$connection) or Die (mysql_error());
	echo "	<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Αλοιφές </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Ointments")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>";
//-------------------------------------------------------------------------------------------------------------------

// για τα αλμυρά extras
$result=mysql_query($query,$connection) or Die (mysql_error());
	echo "	<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Extras </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Sour_Extras")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>
		</tr><tr></tr>";
//-------------------------------------------------------------------------------------------------------------------

// για τις Πραλίνες
$result=mysql_query($query,$connection) or Die (mysql_error());
echo "	<tr>
			<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Πραλίνες </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Chocolates")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>";
//-------------------------------------------------------------------------------------------------------------------

// για τα Specials
$result=mysql_query($query,$connection) or Die (mysql_error());
		echo "<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Specials </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Specials")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>";
//-------------------------------------------------------------------------------------------------------------------

// για τα γλυκά Extras
$result=mysql_query($query,$connection) or Die (mysql_error());
		echo "<th valign=top> 
				<table 	border=\"1\">
					<col width=\"20\" />
					<col width=\"200\" />
					<col width=\"100\" />
					<col width=\"110\" />
					<thead>
						<tr> <th align=\"Center\" colspan=4> Extras </th> </tr>
						<tr> <th>No.</th> <th>Υλικό</th> <th>Τιμή</th> <th>Ποσότητα</th> </tr>
					</thead>
					<tbody>";
						$counter=0;
						while ($row = mysql_fetch_array($result)) 
						{
							if ($row['material_type']=="Sweet_Extras")
							{
							$count_materials.="\"m".$row['material_id']."\",";
							$count_names.="\"".$row['material_name']."\",";
							$count_prices.="\"".$row['material_price']."\",";
							echo "<tr><th>".++$counter."</th><th>".$row['material_name']."<th>".$row['material_price']."</th>";
							echo "<th><input id=\"m".$row['material_id']."\" type=\"text\" id=\"no\" size=\"1\" maxlength=\"2\" value=\"0\"/>
												<input type=\"button\" value=\"+\" onclick=\"increaseValue('m".$row['material_id']."')\"/>
												<input type=\"button\" value=\"-\" onclick=\"decreaseValue('m".$row['material_id']."')\">
														</th> 
													</tr>	";	
							}
						}
					echo "
					</tbody>
				</table>
			</th>
		</tr>";
//-------------------------------------------------------------------------------------------------------------------
$count_materials=substr($count_materials,0,-1);
$count_names=substr($count_names,0,-1);
$count_prices=substr($count_prices,0,-1);
// Επιστροφή global μεταβλητών
	echo "<script>
		var myMats= new Array(".$count_materials.");
		var myNames= new Array(".$count_names.");
		var myPrices= new Array(".$count_prices.");
	</script>";
//----------------------------------------------------

?>

